package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Sign;
import cn.wolfcode.trip.base.service.ISignService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("signs")
public class SignController {

    @Autowired
    private ISignService signService;

    @PostMapping
    public JSONResult sign(Sign sign){
        JSONResult jsonResult = new JSONResult();
        try{
            signService.save(sign);
            return jsonResult;
        }catch (Exception e){
            return jsonResult.mark(e.getMessage());
        }
    }

    /**
     * 查询当前登录用户 今天是否已经签到
     * @return
     */
    @GetMapping
    public JSONResult get(){
        JSONResult result = new JSONResult();
        try {
            signService.get();
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
}
